package app;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import KUtilities.KCipher;

public class User implements Serializable{
	private static final long serialVersionUID = 1L;
	private String username;
	private String password;
	
	public User(String uname,String pass){
		username=uname;
		password=pass;
	}
	
	public User() {
	}

	public void save(File file){
		try {
			file.mkdirs();
			file.delete();
			username=KCipher.encrypt(username);
			password=KCipher.encrypt(password);
			ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(file));
			out.writeObject(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void load(File file){
		try {
			ObjectInputStream in=new ObjectInputStream(new FileInputStream(file));
			User temp=(User)in.readObject();
			username=temp.getUsername();
			password=temp.getPassword();
			username=KCipher.decrypt(username);
			password=KCipher.decrypt(password);
		} catch (Exception e) {}
		
	}
	
	public String getUsername(){
		return username;
	}
	
	public String getPassword(){
		return password;
	}
}
